package com.panda.springcloud.controller;/**
 * @author 乐于吕
 * * @date 2024/10/23
 */

import com.panda.springcloud.entity.Tag;
import com.panda.springcloud.service.TagService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: 乐于吕
 * @CreateTime: 2024-10-23
 * @Description:
 */

@RestController
@RequestMapping("tags")
@Slf4j
public class TagController {

    @Value("${server.port}")
    private String port;
    @Resource
    private TagService tagService;

    // 标签列表
    @GetMapping
    public List<Tag> tagList() {
        return tagService.list();
    }

    // 删除标签
    @DeleteMapping("{id}")
    public Boolean removeTag(@PathVariable("id") Integer id) {

        return tagService.removeById(id);
    }

    // 添加标签
    @PostMapping
    public Tag saveTag(@RequestBody Tag tag) {
        tagService.save(tag);
        return tag;
    }

    // 根据id查询一个标签信息
    @GetMapping("{id}")
    public Tag getTagById(@PathVariable("id") Integer id) {
        return tagService.getById(id);
    }
}